<template>
  <el-dialog
    v-dialogDrag
    :fullscreen="isFullscreen"
    :visible.sync="dialogVisible1"
    :before-close="closeForm"
    width="4rem"
  >
    <div slot="title" class="header-title hd-title">
      <span>{{ dialogTitle1 }}</span>
      <i
        v-if="isFullscreen === false"
        class="el-icon-full-screen"
        @click="fScreen"
      ></i>
      <i v-else class="el-icon-news" @click="ifScreen"></i>
    </div>

    <el-form :model="form" :rules="rules" ref="form" label-width="0.5rem">
      <el-row>
        <el-col :span="12">
          <el-form-item
            label="中文品名"
            :rules="[
              {
                required: true,
                message: '请输入申报中文品名',
                trigger: ['blur', 'change'],
              },
            ]"
            prop="product_title.zh"
          >
            <el-input
              v-if="form.product_title"
              v-model="form.product_title.zh"
              placeholder="请输入申报中文品名"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item
            label="英文品名"
            :rules="[
              {
                required: true,
                message: '请输入申报英文品名',
                trigger: ['blur', 'change'],
              },
            ]"
            prop="product_title.en"
          >
            <el-input
              v-if="form.product_title"
              v-model="form.product_title.en"
              placeholder="请输入申报英文品名"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item
            label="商品颜色"
            prop="specifications.color"
            :rules="[
              {
                required: true,
                message: '请输入相关商品颜色',
                trigger: ['blur', 'change'],
              },
            ]"
          >
            <el-input
              placeholder="请输入商品颜色"
              v-if="form.specifications"
              v-model="form.specifications.color"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item
            label="申报价格"
            :rules="[
              {
                required: true,
                message: '请输入申报价格',
                trigger: ['blur', 'change'],
              },
            ]"
            prop="univalent"
          >
            <el-input
              placeholder="请输入商品申报价格"
              v-model="form.univalent"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item
            label="申报重量"
            :rules="[
              {
                required: true,
                message: '请输入申报重量',
                trigger: ['blur', 'change'],
              },
            ]"
            prop="weight"
          >
            <el-input
              placeholder="请输入商品申报重量"
              v-model="form.weight"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item
            label="申报长度"
            :rules="[
              {
                required: true,
                message: '请输入申报长度',
                trigger: ['blur', 'change'],
              },
            ]"
            prop="volume.L"
          >
            <el-input
              v-if="form.volume"
              v-model="form.volume.L"
              placeholder="请输入申报长度"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item
            label="申报宽度"
            :rules="[
              {
                required: true,
                message: '请输入申报宽度',
                trigger: ['blur', 'change'],
              },
            ]"
            prop="volume.W"
          >
            <el-input
              placeholder="请输入商品宽度"
              v-if="form.volume"
              v-model="form.volume.W"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item
            label="申报高度"
            :rules="[
              {
                required: true,
                message: '请输入申报高度',
                trigger: ['blur', 'change'],
              },
            ]"
            prop="volume.H"
          >
            <el-input
              v-if="form.volume"
              v-model="form.volume.H"
              placeholder="请输入商品高度"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="20">
          <el-form-item
            style="display: inline-block"
            prop="specifications.charged"
          >
            <el-checkbox
              v-if="form.specifications"
              v-model="form.specifications.charged"
              >是否带电?
            </el-checkbox>
          </el-form-item>
          <el-form-item
            style="display: inline-block"
            prop="specifications.liquid"
          >
            <el-checkbox
              v-if="form.specifications"
              v-model="form.specifications.liquid"
              >是否液体?
            </el-checkbox>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer">
      <el-button size="small" type="primary" @click="handleSubmit"
        ><i class="el-icon-circle-plus-outline"></i> 保存
      </el-button>
      <el-button size="small" @click="closeForm"
        ><i class="el-icon-circle-close"></i> 取消
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  props: {
    editData1: {
      type: Object,
      default: () => ({}),
    },
    dialogTitle1: {
      type: String,
      default: "",
    },
    dialogVisible1: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      isFullscreen: false,
      form: {},
      rules: {
        product_title: [
          {
            required: true,
            message: "请输入申报中文品名",
            trigger: ["blur", "change"],
          },
        ],
      },
    };
  },
  watch: {
    editData1: {
      handler(val) {
        this.form = { ...val };
        console.log(this.form);
      },
    },
    dialogVisible1(val) {
      if (val) {
      }
    },
  },
  methods: {
    changeSelectVal(val) {
      this.portInfoValue(val);
    },
    handleSubmit() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.$emit("submit1", this.form);
          this.closeForm();
        }
      });
    },
    closeForm() {
      this.$emit("closeForm");
      this.isFullscreen = false;
      if (this.$refs["form"] !== undefined) {
        this.$refs["form"].resetFields();
      }
    },
    fScreen() {
      this.isFullscreen = true;
    },
    ifScreen() {
      this.isFullscreen = false;
    },
  },
};
</script>
<style lang="scss" scoped>
::v-deep .el-dialog__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #f0f0f0;
}

::v-deep .el-input__inner {
  height: 32px;
  line-height: 32px;
}

::v-deep .el-dialog__body {
  padding: 20px 20px 0 20px;
}

::v-deep .el-dialog__footer {
  padding: 10px 16px;
  border-top: 1px solid #f0f0f0;
}

.el-select-dropdown
  .el-scrollbar
  .el-scrollbar__view
  .el-select-dropdown__item {
  height: auto;
  padding: 0 15px;
}

.hd-title {
  font-size: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex: 1;
  margin-right: 26px;
}

.el-icon-full-screen {
  cursor: pointer;
}

.el-icon-news {
  cursor: pointer;
}
</style>
